//控制单位使用筒子
params ["_unit"];
if(side _unit == east
|| {secondaryWeapon _unit == ""}) exitWith{};//红军不打、或者非筒子兵


private ["_player", "_count"];
	

_count = 0;
while{alive _unit && {_count < 3}}do
{
	sleep 15;
	if((isNull _unit) || (!alive _unit)) exitWith {};
	
	if(simulationEnabled _unit) then{
	
	
		_player = [_unit, 500, 30] call fn_getPlayerAttack;
		//速度与高度差检测
		if (!isNull _player
		&& {speed _player < 30}
		&& {( getPosASL _player select 2) - ( getPosASL _unit select 2) < 20}) then
		{
			sleep 5;


			private _shoot = false;
			//优先载具攻击（不能是飞机）
			if(vehicle _player != _player) then
			{
				_shoot = true;
				[_unit, vehicle _player, 2] call fn_throw;
			};
			//否则选择周围20m坦克
			if(!_shoot) then
			{
				private _list = _player nearObjects ["Tank", 20];
				{
					private _is_red = false;
					if((count crew _x == 0) || {(driver _x) call fn_isPlayerRed}) then{_is_red = true;};
					//if(Param_Debug == 1) then{systemChat str _is_red};
					if(alive _x 
					&& {_is_red}
					&& {[_unit, _x] call fn_checkSee}) exitWith
					{
						_shoot = true;
						[_unit, _x, 2] call fn_throw;
						if(Param_Debug == 1) then{systemChat "AT: 攻击坦克"};
					};
				}forEach _list;
			};
			
			if(!_shoot) then
			{
				//否则选择周围5m汽车
				_list = _player nearObjects ["Car", 8];
				{
					private _is_red = false;
					if((count crew _x == 0) || {(driver _x) call fn_isPlayerRed}) then{_is_red = true;};
					//if(Param_Debug == 1) then{systemChat str _is_red};
					if(alive _x 
					&& {_is_red}
					&& {[_unit, _x] call fn_checkSee}) exitWith
					{
						_shoot = true;
						[_unit, _x, 2] call fn_throw;
						if(Param_Debug == 1) then{systemChat "AT: 攻击汽车"};
					};
				}forEach _list;
			};
			
			if(!_shoot) then
			{
				//否则选择周围5m任何房屋
				_list = _player nearObjects ["House", 8];
				{
					if([_unit, _x] call fn_checkSee) exitWith
					{
						_shoot = true;
						[_unit, _x, 2] call fn_throw;
						if(Param_Debug == 1) then{systemChat "AT: 攻击房屋"};
					};
				}forEach _list;
			};
			
			if(!_shoot) then
			{
				//否则直接攻击
				if([_unit, _player] call fn_checkSee) then
				{
					_shoot = true;
					[_unit, _player, 2] call fn_throw;
					if(Param_Debug == 1) then{systemChat "AT: 攻击单位"};
				};
			};
			
			if(_shoot) then{_count = _count + 1;};
		};
	};
};
						